package com.runfast.paotui.web.controller.user;

import com.runfast.common.web.entity.Result;
import com.runfast.pay.Channel;
import com.runfast.pay.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 支付接口
 */
@RestController("userPayController")
@RequestMapping(value = "/api/user/pay",headers = "token")
public class PayController {

    @Autowired
    private PayService payService;

    /**
     * 获取支付宝或微信预支付信息
     * @param channel 支付渠道
     * @param orderNo 订单号
     * @param request
     * @return
     */
    @PostMapping("prepay")
    public Result<String> prepay(@RequestParam Channel channel, @RequestParam String orderNo, HttpServletRequest request) {
        return payService.prepay(channel, orderNo, request.getRemoteAddr());
    }


    /**
     * 查询订单状态
     * @param orderNo 订单号
     * @return
     */
    @PostMapping("orderQuery")
    public Result orderQuery(@RequestParam String orderNo) {
        return payService.orderQuery(orderNo);
    }


    /**
     * 退款查询
     * @param orderNo 订单号
     * @return
     */
    @PostMapping("refundQuery")
    public Result refundQuery(@RequestParam String orderNo) {
        return payService.refundQuery(orderNo);
    }


}
